/*
 * 作者:熊猫
 * 日期:2017 - 3 - 15 4 - 5 - 23
 *
 */

package net.lainiao.morethread.Chapter6.demo5;

import java.util.Map;
import java.util.concurrent.ConcurrentNavigableMap;
import java.util.concurrent.ConcurrentSkipListMap;

/**
 * Created by Administrator on 2017/3/15.
 */
public class Main {
    public static void main(String[] args) {
        ConcurrentSkipListMap<String,Contack> map=new ConcurrentSkipListMap<>();
        Thread[] threads=new Thread[25];
        int counter=0;
        for (char i = 'A'; i <'Z' ; i++) {
            Task task=new Task(map,String.valueOf(i));
            threads[counter]=new Thread(task);
            threads[counter].start();
            counter++;
        }
        for (int i = 0; i < 25; i++) {
            try {
                threads[i].join();
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
        System.out.println("Main Size of the Map :"+map.size());
        Map.Entry<String,Contack> element=map.firstEntry();
        Contack contack=element.getValue();
        System.out.println("Main : First Entry : "+contack.getName()+" == "+contack.getPhone());
        element=map.lastEntry();
        contack=element.getValue();
        System.out.println("Main : Last Entry : "+contack.getName()+" == "+contack.getPhone());
        System.out.println("Main: SubMap from A1996 to B1002");
        ConcurrentNavigableMap<String,Contack> subMap=map.subMap("A1996","B1002");
        do{
            element=subMap.pollFirstEntry();
            if(element!=null){
                contack=element.getValue();
                System.out.println(contack.getName()+" : "+contack.getPhone());
            }
        }while(element!=null);
        System.out.println("Main over");
    }
}
